package za.co.smartmi.service.exception;

import za.co.smartmi.server.model.ServiceError;
import java.util.ArrayList;
import java.util.List;

public class ServiceException extends Exception {
    
    protected List<ServiceError> errors;
    
    protected ServiceError error;
    
    public ServiceException(Throwable cause) {
        super(cause);
    }

    public ServiceException(String message, Throwable cause) {
        super(message, cause);
    }

    public ServiceException(String message) {
        super(message);
    }
    
    /**
     * Use this if you have more than one error to report
     * @param message
     * @param errors 
     */
    public ServiceException(String message, List<ServiceError> errors ) {
        super(message);
        this.getErrors().addAll(errors);        
    }
    
    /**
     * Use this for one error, as alternative choice
     * @param message
     * @param error 
     */
    public ServiceException(String message, ServiceError error ) {
        super(message);
        this.error = error;        
    }     

    public ServiceException() {
    }

    public ServiceError getError() {
        return error;
    }

    /**
     * Gets the value of the errors property.
     * 
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the object.
     * This is why there is not a <CODE>set</CODE> method for the errors property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getErrors().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link ServiceError }
     * 
     * 
     */
    public List<ServiceError> getErrors() {
        if (errors == null) {
            errors = new ArrayList<ServiceError>();
        }
        return this.errors;
    }    
    
}
